package tech.summerly.weather.util

import tech.summerly.weather.R

/**
 * more please see
 * http://bz.mep.gov.cn/bzwb/dqhjbh/jcgfffbz/201203/W020120410332725219541.pdf
 */
enum class Aqi {

    Excellent,
    Good,
    LightlyPolluted,
    ModeratelyPolluted,
    HeavilyPolluted,
    SeverelyPolluted;

    companion object {


        fun from(aqi: Int): Aqi = when {
            aqi in 0..50 -> Excellent
            aqi in 51..100 -> Good
            aqi in 101..150 -> LightlyPolluted
            aqi in 151..200 -> ModeratelyPolluted
            aqi in 201..300 -> HeavilyPolluted
            aqi > 300 -> SeverelyPolluted
            else -> throw IllegalArgumentException()
        }
    }


    fun localString(): String = when (this) {
        Excellent -> "优"
        Good -> "良"
        LightlyPolluted -> "轻度污染"
        ModeratelyPolluted -> "中度污染"
        HeavilyPolluted -> "重度污染"
        SeverelyPolluted -> "严重污染"
    }

    fun healthEffects(): String = when (this) {
        Excellent -> "空气质量令人满意，基本无空气污染"
        Good -> "空气质量可接受，但某些污染物可能对极少数异常敏感人群健康有较弱影响"
        LightlyPolluted -> "易感人群症状有轻度加剧，健康人群出现刺激症状"
        ModeratelyPolluted -> "进一步加剧易感人群症状，可能对健康人群心脏、呼吸系统有影响"
        HeavilyPolluted -> "心脏病和肺病患者症状显著加剧，运动耐受力降低，健康人群普遍出现症状"
        SeverelyPolluted -> "健康人群运动耐受力降低，有明显强烈症状，提前出现某些疾病"
    }

    fun suggest(): String = when (this) {
        Excellent -> "各类人群可正常活动"
        Good -> "极少数异常敏感人群应减少户外活动"
        LightlyPolluted -> "儿童、老年人及心脏病、呼吸系统疾病患者避免长时间、高强度的户外锻炼。"
        ModeratelyPolluted -> "儿童、老年人及心脏病、呼吸系统疾病患者避免长时间、高强度的户外锻炼，一般人适量减少户外运动"
        HeavilyPolluted -> "儿童、老年人和心脏病、肺病患者应停留在室内，停止户外运动。一般人群减少户外运动"
        SeverelyPolluted -> "儿童、老年人和病人应当留在室内，避免体力消耗，一般人群应避免户外活动"
    }

    /**
     * @return color int
     */
    fun color(): Int = when (this) {
        Excellent -> tech.summerly.weather.util.color(R.color.color_aqi_excellent)
        Good -> tech.summerly.weather.util.color(R.color.color_aqi_good)
        LightlyPolluted -> tech.summerly.weather.util.color(R.color.color_aqi_lightly_polluted)
        ModeratelyPolluted -> tech.summerly.weather.util.color(R.color.color_aqi_moderately_polluted)
        HeavilyPolluted -> tech.summerly.weather.util.color(R.color.color_aqi_heavily_polluted)
        SeverelyPolluted -> tech.summerly.weather.util.color(R.color.color_aqi_severely_polluted)
    }
}